(function (vc) {

    vc.extends({
        propTypes: {
            callBackListener: vc.propTypes.string, //父组件名称
            callBackFunction: vc.propTypes.string //父组件监听方法
        },
        data: {
            addAffiliateProductInfo: {
                productId: '',
                seq: '',

            }
        },
        _initMethod: function () {

        },
        _initEvent: function () {
            vc.on('addAffiliateProduct', 'openAddAffiliateProductModal', function () {
                $('#addAffiliateProductModel').modal('show');
            });
        },
        methods: {
            addAffiliateProductValidate() {
                return vc.validate.validate({
                    addAffiliateProductInfo: vc.component.addAffiliateProductInfo
                }, {
                    'addAffiliateProductInfo.productId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "商品编号不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "商品编号太长"
                        },
                    ],
                    'addAffiliateProductInfo.seq': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "排序不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "32",
                            errInfo: "排序必须是整数"
                        },
                    ],


                });
            },
            saveAffiliateProductInfo: function () {
                if (!vc.component.addAffiliateProductValidate()) {
                    vc.toast(vc.validate.errInfo);

                    return;
                }

                vc.component.addAffiliateProductInfo.communityId = vc.getCurrentCommunity().communityId;
                //不提交数据将数据 回调给侦听处理
                if (vc.notNull($props.callBackListener)) {
                    vc.emit($props.callBackListener, $props.callBackFunction, vc.component.addAffiliateProductInfo);
                    $('#addAffiliateProductModel').modal('hide');
                    return;
                }

                vc.http.apiPost(
                    'affiliateProduct.saveAffiliateProduct',
                    JSON.stringify(vc.component.addAffiliateProductInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#addAffiliateProductModel').modal('hide');
                            vc.component.clearAddAffiliateProductInfo();
                            vc.emit('affiliateProductManage', 'listAffiliateProduct', {});

                            return;
                        }
                        vc.message(_json.msg);

                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');

                        vc.message(errInfo);

                    });
            },
            clearAddAffiliateProductInfo: function () {
                vc.component.addAffiliateProductInfo = {
                    productId: '',
                    seq: '',
                };
            }
        }
    });

})(window.vc);
